package com.example.expinterview.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.expinterview.dto.CollectDto;
import com.example.expinterview.entity.EiCollect;
import com.example.expinterview.entity.ResultBody;
import com.example.expinterview.service.IEiCollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @classname: CollectController
 * @description: TODO
 * @author: kaiser
 * @date: 2021/10/20 16:06
 * @version: 1.0
 */
@RestController
@RequestMapping("/collect")
@Api(tags = "收藏")
public class CollectController {
    private final IEiCollectService service;

    @Autowired
    public CollectController(IEiCollectService service) {
        this.service = service;
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "修改或创建收藏")
    public ResultBody save(@RequestBody EiCollect collect) {
        return service.create(collect);
    }

    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据id获取")
    public ResultBody getById(@PathVariable Long id) {
        return ResultBody.success(service.getById(id));
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除")
    public ResultBody delete(@RequestBody CollectDto collect) {
        return service.cancelCollect(collect);
    }

    @GetMapping("/list/{userId}")
    @ApiOperation(value = "根据userId获取收藏记录")
    public ResultBody list(@PathVariable Long userId) {
        return service.listByUser(userId);
    }

    @PostMapping("/status")
    @ApiOperation(value = "根据用户id和文章id判断是否被用户收藏")
    public ResultBody status(@RequestBody CollectDto collect) {
        return service.checkCollect(collect);
    }
}
